package com.jy.api.dao;

import com.jy.api.domain.Num;
import com.jy.api.domain.Region;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

public interface NumDao  extends JpaRepository<Num, Integer>, JpaSpecificationExecutor<Num> {


    @Query(value = "SELECT `store_id` , SUM( `status`=1) , SUM( `status` =2)  FROM `num`   WHERE  `update_time`  >=? GROUP BY `store_id`", nativeQuery = true)
    List<Object[]> findByStoreId(Date beforeTenMinTime);

    @Query(value = "SELECT `store_id`   FROM `num` GROUP BY `store_id`", nativeQuery = true)
    List<String> findAllStoreId();


    Num findTop1ByStoreIdOrderByQueueDesc(String storeId);


    long countByStatusInAndStoreId(List<Integer> status,String storeId);

    long countByStoreId(String storeId);

    @Query(value = "SELECT count(`id`) FROM `num`   WHERE  `update_time`  >=? and `store_id` =? and `status`=1", nativeQuery = true)
    long countByStoreId(Date beforeTenMinTime,String storeId);
}
